<template>
    <el-config-provider :locale="locale" :size="assemblySize" :button="buttonConfig">
        <router-view></router-view>
    </el-config-provider>
</template>

<script setup>
import { onMounted, reactive, computed } from 'vue'
import { ElConfigProvider } from 'element-plus'
import { useI18n } from 'vue-i18n'
import en from 'element-plus/es/locale/lang/en'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { getBrowserLang } from '@/utils'
import { useTheme } from '@/hooks/useTheme'
import { useGlobalStore } from '@/store/modules/global'
import { setStorage } from '@/utils/storage.js'

const globalStore = useGlobalStore()

if (import.meta.env.VITE_USER_NODE_ENV === 'development') {
    setStorage('moduleCode', '2')
    setStorage('appCode', '11')

    setStorage('authToken', '58e168e6-3d00-47f1-8552-b04795452824')
    setStorage('masterOrgId', '114024416462213120')
    setStorage('orgId', '114024416462213120')
}

// init theme11
const { initTheme } = useTheme()
initTheme()

// init language
const i18n = useI18n()
onMounted(() => {
    const language = globalStore.language ?? getBrowserLang()
    i18n.locale.value = language
    globalStore.setGlobalState('language', language)
})

// 普通pnpm i 安装
// element language
const locale = computed(() => {
    if (globalStore.language === 'zh') return zhCn
    if (globalStore.language === 'en') return en
    return getBrowserLang() === 'zh' ? zhCn : en
})

// element assemblySize
const assemblySize = computed(() => globalStore.assemblySize)

// element button config
const buttonConfig = reactive({ autoInsertSpace: false })
</script>
